<?php
	//将提交的内容保存到本地json文件
	$fname = $_POST['fname'];
	$fage = $_POST['fage'];
	$json_string = file_get_contents('User.json'); 
    // 用参数true把JSON字符串强制转成PHP数组    
    $data = json_decode($json_string, true);
    $len = count($data);
    $res = [];
    $res['name'] = $fname;
    $res['age'] = $fage;
    $res['id'] = $data[$len - 1]['id'] + 1;
    $data[$len] = $res;
    // 把PHP数组转成JSON字符串
    $json_str = json_encode($data);
    // 写入文件
    file_put_contents('User.json', $json_str);
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>提交显示</title>
</head>
<body>
	<div>
		<h1>您提交的内容是</h1>
		<div>
			Name: <?php echo $_POST['fname']?>
		</div>
		<div>
			Age: <?php echo $_POST['fage']?>
		</div>
	</div>
</body>
</html>